<?php
require '../../lib/init.php';

function getTitle($page_id='id_btn_home') {
    global $smarty;
    global $gCn;
    switch ($page_id) {
        case 'id_btn_home':
            $sql = 'SELECT * FROM objects WHERE show_front = true ORDER by object_id DESC OFFSET 0 LIMIT 6;';
            $gCn->Execute($sql);
            $gCn->MoveFirst();
            while(!$gCn->EOF()) {
                $arrObjects[]=array(
                        'object_id'=>$gCn->mRs['object_id'],
                        'name'=>$gCn->mRs['name'],
                        'thumb_src'=>preg_replace('/(\.[a-zA-Z]{3,4})/', '_t${1}', $gCn->mRs['thumb_src']),
                        'descr'=>nl2br($gCn->mRs['descr'])
                );
                $gCn->MoveNext();
            }
            $smarty->assign('arrObjects',$arrObjects);
            $smarty->assign('template_name','home');
            break;
    }
}

function LoadTitle($template_name) {
    global $smarty;
    $smarty->display($template_name);
} 


if($_POST['buttonId']) {
    $buttonId=$_POST['buttonId'];
    switch($buttonId) {
        case 'id_btn_home':
            getTitle('id_btn_home');
            LoadTitle('title_home.tpl');
            break;
        case 'id_btn_portfolio':LoadTitle('title_portfolio.tpl');
            break;
        case 'id_btn_clients':LoadTitle('title_clients.tpl');
            break;
        case 'id_btn_campaigns':LoadTitle('title_campaigns.tpl');
            break;
        case 'id_btn_contacts':LoadTitle('title_contacts.tpl');
            break;
        case 'id_btn_reklama':LoadTitle('title_reklama.tpl');
            break;
        case 'id_btn_contacts':
            LoadTitle('title_contacts.tpl');
            break;
    }
}






